package com.museum.guide.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.museum.guide.common.result.Result;
import com.museum.guide.entity.MuseumMap;
import com.museum.guide.service.MuseumMapService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/map")
public class MuseumMapController {

    @Resource
    private MuseumMapService museumMapService;

    /**
     * 分页查询地图信息
     */
    @GetMapping("/page")
    public Result<Page<MuseumMap>> page(
            Page<MuseumMap> page,
            String name,
            String floor,
            Integer status) {
        return Result.success(museumMapService.page(page, name, floor, status));
    }

    /**
     * 获取所有启用的地图列表
     */
    @GetMapping("/listEnabled")
    public Result<List<MuseumMap>> listEnabled() {
        return Result.success(museumMapService.listEnabled());
    }

    /**
     * 根据楼层获取地图
     */
    @GetMapping("/listByFloor")
    public Result<List<MuseumMap>> listByFloor(@RequestParam String floor) {
        return Result.success(museumMapService.listByFloor(floor));
    }

    /**
     * 新增地图
     */
    @PostMapping("/add")
    public Result<Void> save(@RequestBody @Valid MuseumMap museumMap) {
        museumMapService.saveMap(museumMap);
        return Result.success();
    }

    /**
     * 更新地图信息
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody @Valid MuseumMap museumMap) {
        museumMapService.updateMap(museumMap);
        return Result.success();
    }

    /**
     * 删除地图
     */
    @DeleteMapping("/removeById")
    public Result<Void> remove(Long id) {
        museumMapService.removeMap(id);
        return Result.success();
    }

    /**
     * 启用/禁用地图
     */
    @PostMapping("/updateStatus")
    public Result<Void> updateStatus(@RequestParam Long id, @RequestParam Integer status) {
        museumMapService.updateStatus(id, status);
        return Result.success();
    }
}